<?php

require_once(sfConfig::get('sf_lib_dir').'/filter/base/BaseFormFilterPropel.class.php');

/**
 * Narudzbina filter form base class.
 *
 * @package    marketing
 * @subpackage filter
 * @author     Your name here
 */
class BaseNarudzbinaFormFilter extends BaseFormFilterPropel
{
  public function setup()
  {
    $this->setWidgets(array(
      'datum_narudzbine'        => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'status_id'               => new sfWidgetFormPropelChoice(array('model' => 'Status', 'add_empty' => true)),
      'kupac_id'                => new sfWidgetFormPropelChoice(array('model' => 'Kupac', 'add_empty' => true)),
      'nacin_placanja_id'       => new sfWidgetFormPropelChoice(array('model' => 'NacinPlacanja', 'add_empty' => true)),
      'nacin_isporuke_id'       => new sfWidgetFormPropelChoice(array('model' => 'NacinIsporuke', 'add_empty' => true)),
      'created_at'              => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => true)),
      'updated_at'              => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => true)),
      'deleted_at'              => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => true)),
      'narudzbina_prozvod_list' => new sfWidgetFormPropelChoice(array('model' => 'Proizvod', 'add_empty' => true)),
    ));

    $this->setValidators(array(
      'datum_narudzbine'        => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDate(array('required' => false)))),
      'status_id'               => new sfValidatorPropelChoice(array('required' => false, 'model' => 'Status', 'column' => 'id')),
      'kupac_id'                => new sfValidatorPropelChoice(array('required' => false, 'model' => 'Kupac', 'column' => 'id')),
      'nacin_placanja_id'       => new sfValidatorPropelChoice(array('required' => false, 'model' => 'NacinPlacanja', 'column' => 'id')),
      'nacin_isporuke_id'       => new sfValidatorPropelChoice(array('required' => false, 'model' => 'NacinIsporuke', 'column' => 'id')),
      'created_at'              => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDate(array('required' => false)))),
      'updated_at'              => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDate(array('required' => false)))),
      'deleted_at'              => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDate(array('required' => false)))),
      'narudzbina_prozvod_list' => new sfValidatorPropelChoice(array('model' => 'Proizvod', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('narudzbina_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    parent::setup();
  }

  public function addNarudzbinaProzvodListColumnCriteria(Criteria $criteria, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $criteria->addJoin(NarudzbinaProzvodPeer::NARUDZBINA_ID, NarudzbinaPeer::ID);

    $value = array_pop($values);
    $criterion = $criteria->getNewCriterion(NarudzbinaProzvodPeer::PROIZVOD_ID, $value);

    foreach ($values as $value)
    {
      $criterion->addOr($criteria->getNewCriterion(NarudzbinaProzvodPeer::PROIZVOD_ID, $value));
    }

    $criteria->add($criterion);
  }

  public function getModelName()
  {
    return 'Narudzbina';
  }

  public function getFields()
  {
    return array(
      'id'                      => 'Number',
      'datum_narudzbine'        => 'Date',
      'status_id'               => 'ForeignKey',
      'kupac_id'                => 'ForeignKey',
      'nacin_placanja_id'       => 'ForeignKey',
      'nacin_isporuke_id'       => 'ForeignKey',
      'created_at'              => 'Date',
      'updated_at'              => 'Date',
      'deleted_at'              => 'Date',
      'narudzbina_prozvod_list' => 'ManyKey',
    );
  }
}
